/**
 * Created by Administrator on 16-2-22.
 */
/**
 * Created by novem on 2016/2/2.
 */
define([
    "jquery",
    "IO",
    "UPLOADUI",
    "UPLOAD",
    "jqueryUI",
    "bootbox",
    //"text!/js/biz/keb/activity/definebt.html"
], function ($, IO, upui, up, jui, bootbox, definebt) {
    $('#fileupload').fileupload({
        url: '/upload',
        dataType: 'json',
        autoUpload: true,
        acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
        maxFileSize: 10000000, // 10 MB
        disableImageResize: /Android(?!.*Chrome)|Opera/
            .test(window.navigator.userAgent),
        previewMaxWidth: 150,
        previewMaxHeight: 150,
        previewCrop: true
    }).on('fileuploadadd', function (e, data) {
        document.getElementById('upimgs').src = '/images/loading.gif';

    }).on('fileuploadprocessalways', function (e, data) {
        //console.log("fileuploadprocessalways",data);
    }).on('fileuploadprogressall', function (e, data) {
        //console.log("fileuploadprogressall",data);
    }).on('fileuploaddone', function (e, data) {
        var alt = $(e.target).attr('alt');
        if (!alt)
            alt = '';
        console.log("#upimgs" + alt);
        $("#upimgs" + alt).attr("src", data._response.result.url);
    });
    //编辑资讯
    $(document).on("click",".publish",function(){
        var info_id = $("#info_id").attr('value');
        var category_name = $(".categ option:selected").val();
        var category_id = $(".categ option:selected").attr("data-id");
        var title = $("#title").val();
        var cover = $("#upimgs").attr("src");
        var content=editor.html();

        var param={info_id:info_id,category_name:category_name,category_id:category_id,content:content,title:title};

        if(category_id&&category_id!=undefined){
            param.category_id = category_id;
        }else{
            alert("请选择资讯类型~");
            return;
        }
        if(title==""){
            alert("请输入资讯标题");
        }
        if(content==""){
            alert("请输入资讯内容");
            return;
        }
        if(cover){
            param.cover=cover;
        }else{
            alert("请上传照片");
            return
        }
        if(param&&param!='undefined'){
            bootbox.confirm("确定要修改该资讯？",function(result){
                if(result) {
                    IO.post("act/update_inform",param,function(d){
                        bootbox.alert(d.msg,function(){
                            if (d.code == 0) {
                                location.href = '/pte/informlb';
                            }
                        });
                    });
                }
            });
        }
    });


});